
#include <iostream>
#include <memory>
#include "Reactor.hpp"
#include "Log.hpp"
#include "Connection.hpp"
#include "Listener.hpp"
#include "PackgeParse.hpp"
#include "HandlerConnection.hpp"

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << "Usage: " << argv[0] << " port" << std::endl;
        return 0;
    }
    uint16_t port = std::atoi(argv[1]);
    std::unique_ptr<Reactor> server = std::make_unique<Reactor>(); // 主server

    HandlerConnection hc(PackgeParse::Parse); // IO 通信，不管协议，回调上层业务处理

    Listener listen(port, hc); // 负责链接的模块
    // 注册进入
    server->AddConnection(
        listen.Sockfd(),
        EPOLLIN | EPOLLET,
        std::bind(&Listener::Accepter, &listen, std::placeholders::_1),
        nullptr,
        nullptr);
    // 事件排派发
    server->Dispatcher();

    return 0;
}